package com.ssm.demo.controller.login;

import com.ssm.demo.service.tbuser.bean.User;
import com.ssm.demo.service.tbuser.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("login")
public class LoginController {



    @Autowired
    private IUserService userService;

    /**
     * 获取登录用户名
     * @return
     */
    @RequestMapping("getName")
    public Map<String, Object> getName(){
        String name = SecurityContextHolder.getContext().getAuthentication().getName();
        Map<String, Object> map = new HashMap<>();
        map.put("loginName", name);
        return map;
    }

    @RequestMapping("getUser")
    public User getUser(){
        User user = userService.getById("1");
        System.out.println("user" + user);
        return user;
    }

}
